//////////////////////////////////////////////////////////////////////////////////
//
// ActionScript 3.0 Common Library (MIT License)
// Copyright (c) 2009 AS3CommonCode | Tony Birleffi | http://www.mosaiceye.com
// 
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// The following people are credited with originating all or parts of this code:
// FlashDoctors | flashdoctors.sourceforge.net
//
//////////////////////////////////////////////////////////////////////////////////

package org.as3commoncode.net
{
	import flash.system.Capabilities;	import org.as3commoncode.net.IFile;
	import org.as3commoncode.net.URL;
	
	/**
	 * AbstractFile class is an abstract representation of a web related file.
	 * 
	 * @see	org.as3commoncode.net.IFile;
	 * @author Tony Birleffi
	 */
	public class AbstractFile implements IFile
	{
		private var sub:IFile;
		public static var SWF:Number = 0;
		public static var IMG:Number = 1;
		public static var XML:Number = 2;
		public static var VID:Number = 3;
		public static var SND:Number = 3;
		
	    /**
	     * Constructor.
	     */
	    public function AbstractFile()
	    {
	        sub = IFile(this);
	        if(sub == null) throw("Classes extending AbstractFile must implement IFile");
	    }
	    
	    /**
	     * Separates a string.
	     * 
	     * @return String.
	     */
	    public static function separator():String
	    {
    		var s:String = "\\";
    		if(Capabilities.os.indexOf("Mac") == 0 || Capabilities.os.indexOf("Lin") == 0) s = "/";
    		return s;
	    }
	    
	    /**
	     * If the path is absolute.
	     * 
	     * @return Boolean.
	     */
	    public function isAbsolute():Boolean
		{
			if(this is URL || getFullPath().indexOf("/") == 0 || getFullPath().indexOf("file:") == 0) return true;
			return false;
		}
		
		/**
		 * If the path is to a directory.
		 * 
		 * @return Boolean.
		 */
		public function isDirectory():Boolean
		{
			if(getFilename() == null || getFilename() == "") return true;
			return false;
		}
		
		/**
		 * If the path is to a file.
		 * 
		 * @return Boolean.
		 */
		public function isFile():Boolean
		{
			if(!isDirectory()) return true;
			return false;	
		}
		
		/**
		 * If the path is an url.
		 * 
		 * @return Boolean.
		 */
		public function isUrl():Boolean
		{
			return this is URL;
		}
		
		/**
		 * Get the paths extenstion.
		 * 
		 * @return String.
		 */
		public function getExtenstion():String
		{
			var fileName:String = getFilename();
			return fileName.substr(fileName.lastIndexOf(".")+1,fileName.length);
		}
		
		/**
		 * Get the file type.
		 * 
		 * @return Number.
		 */
		public function getType():Number
	    {
	    	var ext:String = getExtenstion().toLowerCase();
	    	var type:Number;
			
			switch(ext)
			{
				case "swf" : 
	 				type = AbstractFile.SWF;
	 				break;
	 			case "jpg" : 
	 				type = AbstractFile.IMG;
	 				break;
	 			case "gif" : 
	 				type = AbstractFile.IMG;
	 				break;
	 			case "png" : 
	 				type = AbstractFile.IMG;
	 				break;
	 			case "svg" : 
	 				type = AbstractFile.IMG;
	 				break;
	 			case "mov" : 
	 				type = AbstractFile.VID;
	 				break;
	 			case "flv" : 
	 				type = AbstractFile.VID;
	 				break;
	 			case "xml" : 
	 				type = AbstractFile.XML;
	 				break;
	 			case "mp3" : 
	 				type = AbstractFile.SND;
	 				break;
	 			case "wav" : 
	 				type = AbstractFile.SND;
	 				break;
			}
			return type;
	    }
	    
		/**
		 * Get the full path.
		 * 
		 * @return String.
		 */
		public function getFullPath():String
		{
			return null;
		}
		
		/**
		 * Get the file name.
		 * 
		 * @return String.
		 */
		public function getFilename():String
		{
			return null;
		}
		
		/**
		 * Get the path.
		 * 
		 * @return String.
		 */
		public function getPath():String
		{
			return null;
		}
	}
}
